﻿using System.ComponentModel;

namespace TrinityCreator.Data
{
    public class ItemSubClass : IKeyValue, INotifyPropertyChanged
    {
        private ItemInventoryType[] _lockedInventoryType;
        private ItemMaterial _material;
        private string _previewNoteLeft;
        private string _previewNoteRight;

        public ItemSubClass(int id, string description, string previewNoteLeft = "", string previewNoteRight = "",
            ItemInventoryType[] lockedInventoryType = null, ItemMaterial material = null)
        {
            Id = id;
            Description = description;
            PreviewNoteLeft = previewNoteLeft;
            PreviewNoteRight = previewNoteRight;
            LockedInventoryType = lockedInventoryType;
            Material = material;
        }

        public string PreviewNoteLeft
        {
            get
            {
                if (LockedInventoryType == null)
                {
                    if (_previewNoteLeft == "")
                        return Description;
                    return PreviewNoteLeft;
                }
                return LockedInventoryType[0].Description;
            }
            set
            {
                _previewNoteLeft = value;
                RaisePropertyChanged("PreviewNoteLeft");
            }
        }

        public string PreviewNoteRight
        {
            get
            {
                if (_previewNoteRight == "" && _previewNoteRight != PreviewNoteLeft)
                    return Description;
                return _previewNoteRight;
            }
            set
            {
                _previewNoteRight = value;
                RaisePropertyChanged("PreviewNoteRight");
            }
        }

        public ItemInventoryType[] LockedInventoryType
        {
            get
            {
                if (_lockedInventoryType == null)
                    return ItemInventoryType.GetNonEquipable();
                return _lockedInventoryType;
            }
            set
            {
                _lockedInventoryType = value;
                RaisePropertyChanged("LockedInventoryType");
            }
        }

        public ItemMaterial Material
        {
            get
            {
                if (_material == null)
                {
                    return ItemMaterial.GetUndefined();
                }
                return _material;
            }
            set
            {
                _material = value;
                RaisePropertyChanged("Material");
            }
        }

        public int Id
        {
            get { return base.Id; }
            set
            {
                base.Id = value;
                RaisePropertyChanged("Id");
            }
        }

        public string Description
        {
            get { return base.Description; }
            set
            {
                base.Description = value;
                RaisePropertyChanged("Description");
            }
        }

        public override string ToString()
        {
            return Description;
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void RaisePropertyChanged(string property)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(property));
        }

        public static ItemSubClass[] GetMiscellaneousList()
        {
            return new[]
            {
                new ItemSubClass(0, "垃圾"),
                new ItemSubClass(1, "药剂"),
                new ItemSubClass(2, "宠物"),
                new ItemSubClass(3, "节日"),
                new ItemSubClass(4, "其它"),
                new ItemSubClass(5, "坐骑")
            };
        }

        public static ItemSubClass[] GetKeyList()
        {
            return new[]
            {
                new ItemSubClass(0, "钥匙"),
                new ItemSubClass(1, "开锁工具")
            };
        }

        public static ItemSubClass[] GetQuestList()
        {
            return new[]
            {
                new ItemSubClass(0, "任务")
            };
        }

        public static ItemSubClass[] GetQuiverList()
        {
            return new[]
            {
                new ItemSubClass(2, "箭袋"),
                new ItemSubClass(3, "子弹袋")
            };
        }

        public static ItemSubClass[] GetRecipeList()
        {
            return new[]
            {
                new ItemSubClass(0, "书"),
                new ItemSubClass(1, "制皮"),
                new ItemSubClass(2, "裁缝"),
                new ItemSubClass(3, "工程"),
                new ItemSubClass(4, "锻造"),
                new ItemSubClass(5, "烹饪"),
                new ItemSubClass(6, "炼金"),
                new ItemSubClass(7, "急救"),
                new ItemSubClass(8, "附魔"),
                new ItemSubClass(9, "钓鱼"),
                new ItemSubClass(10, "珠宝加工")
            };
        }

        public static ItemSubClass[] GetTradeGoodsList()
        {
            return new[]
            {
                new ItemSubClass(0, "商业物品(制造的)"),
                new ItemSubClass(1, "零件"),
                new ItemSubClass(2, "火药炸弹"),
                new ItemSubClass(3, "工程物品"),
                new ItemSubClass(4, "珠宝加工"),
                new ItemSubClass(5, "布料"),
                new ItemSubClass(6, "皮革"),
                new ItemSubClass(7, "金属或石头"),
                new ItemSubClass(8, "肉"),
                new ItemSubClass(9, "药草"),
                new ItemSubClass(10, "元素"),
                new ItemSubClass(11, "其它"),
                new ItemSubClass(12, "附魔"),
                new ItemSubClass(13, "原材料"),
                new ItemSubClass(14, "护甲附魔"),
                new ItemSubClass(15, "武器附魔")
            };
        }

        public static ItemSubClass[] GetProjectileList()
        {
            var ammoType = ItemInventoryType.GetAmmo();
            return new[]
            {
                new ItemSubClass(2, "箭头", lockedInventoryType: ammoType),
                new ItemSubClass(3, "弹药", lockedInventoryType: ammoType)
            };
        }

        public static ItemSubClass[] GetReagentList()
        {
            return new[]
            {
                new ItemSubClass(0, "药剂")
            };
        }

        public static ItemSubClass[] GetArmorList()
        {
            var armorType = ItemInventoryType.GetArmor();
            var relicType = ItemInventoryType.GetRelic();

            return new[]
            {
                new ItemSubClass(1, "布甲", lockedInventoryType: armorType, material: ItemMaterial.GetCloth()),
                new ItemSubClass(2, "皮甲", lockedInventoryType: armorType, material: ItemMaterial.GetLeather()),
                new ItemSubClass(3, "锁甲", lockedInventoryType: armorType, material: ItemMaterial.GetChain()),
                new ItemSubClass(4, "板甲", lockedInventoryType: armorType, material: ItemMaterial.GetPlate()),
                new ItemSubClass(6, "盾牌", lockedInventoryType: ItemInventoryType.GetShield(),
                    material: ItemMaterial.GetPlate()),
                new ItemSubClass(7, "圣契", lockedInventoryType: relicType),
                new ItemSubClass(8, "神像", lockedInventoryType: relicType),
                new ItemSubClass(9, "图腾", lockedInventoryType: relicType),
                new ItemSubClass(10, "印章", lockedInventoryType: relicType),
                new ItemSubClass(0, "其它 戒指等", lockedInventoryType: ItemInventoryType.GetAllInventoryTypes())
            };
        }

        public static ItemSubClass[] GetGemList()
        {
            return new[]
            {
                new ItemSubClass(0, "红色"),
                new ItemSubClass(1, "蓝色"),
                new ItemSubClass(2, "黄色"),
                new ItemSubClass(3, "紫色"),
                new ItemSubClass(4, "绿色"),
                new ItemSubClass(5, "橙色"),
                new ItemSubClass(6, "原石"),
                new ItemSubClass(7, "简易"),
                new ItemSubClass(8, "棱彩")
            };
        }

        public static ItemSubClass[] GetWeaponList()
        {
            return new[]
            {
                new ItemSubClass(0, "单手斧", previewNoteRight: "斧",
                    lockedInventoryType: ItemInventoryType.GetOneHandWeapon()),
                new ItemSubClass(1, "双手斧", previewNoteRight: "斧",
                    lockedInventoryType: ItemInventoryType.GetTwoHandWeapon()),
                new ItemSubClass(2, "弓", lockedInventoryType: ItemInventoryType.GetRangedBow()),
                new ItemSubClass(3, "枪械", lockedInventoryType: ItemInventoryType.GetRangedWandGun()),
                new ItemSubClass(4, "单手锤", previewNoteRight: "锤",
                    lockedInventoryType: ItemInventoryType.GetOneHandWeapon()),
                new ItemSubClass(5, "双手锤", previewNoteRight: "锤",
                    lockedInventoryType: ItemInventoryType.GetTwoHandWeapon()),
                new ItemSubClass(6, "长柄武器", lockedInventoryType: ItemInventoryType.GetTwoHandWeapon()),
                new ItemSubClass(7, "单手剑", previewNoteRight: "剑",
                    lockedInventoryType: ItemInventoryType.GetOneHandWeapon()),
                new ItemSubClass(8, "双手剑", previewNoteRight: "剑",
                    lockedInventoryType: ItemInventoryType.GetTwoHandWeapon()),
                new ItemSubClass(10, "法杖", lockedInventoryType: ItemInventoryType.GetTwoHandWeapon()),
                new ItemSubClass(13, "拳套", lockedInventoryType: ItemInventoryType.GetOneHandWeapon()),
                new ItemSubClass(14, "锄头铁锤", lockedInventoryType: ItemInventoryType.GetAllInventoryTypes()),
                new ItemSubClass(15, "匕首", lockedInventoryType: ItemInventoryType.GetOneHandWeapon()),
                new ItemSubClass(16, "投掷武器", lockedInventoryType: ItemInventoryType.GetThrown()),
                new ItemSubClass(18, "弩", lockedInventoryType: ItemInventoryType.GetRangedBow()),
                new ItemSubClass(19, "魔杖", lockedInventoryType: ItemInventoryType.GetRangedWandGun()),
                new ItemSubClass(20, "鱼竿", lockedInventoryType: ItemInventoryType.GetTwoHandWeapon())
            };
        }

        public static ItemSubClass[] GetContainerList()
        {
            var bagType = ItemInventoryType.GetBag();
            return new[]
            {
                new ItemSubClass(0, "容器", lockedInventoryType: bagType),
                new ItemSubClass(1, "灵魂袋", lockedInventoryType: bagType),
                new ItemSubClass(2, "草药袋", lockedInventoryType: bagType),
                new ItemSubClass(3, "附魔材料袋", lockedInventoryType: bagType),
                new ItemSubClass(4, "工程材料袋", lockedInventoryType: bagType),
                new ItemSubClass(5, "宝石袋", lockedInventoryType: bagType),
                new ItemSubClass(6, "矿石袋", lockedInventoryType: bagType),
                new ItemSubClass(7, "制皮袋", lockedInventoryType: bagType),
                new ItemSubClass(8, "铭文袋", lockedInventoryType: bagType)
            };
        }

        public static ItemSubClass[] GetConsumableList()
        {
            return new[]
            {
                new ItemSubClass(0, "消耗品", material: ItemMaterial.GetConsumable()),
                new ItemSubClass(1, "毒药", material: ItemMaterial.GetConsumable()),
                new ItemSubClass(2, "炼金", material: ItemMaterial.GetConsumable()),
                new ItemSubClass(3, "瓶", material: ItemMaterial.GetConsumable()),
                new ItemSubClass(4, "卷轴", material: ItemMaterial.GetConsumable()),
                new ItemSubClass(5, "食物和饮料", material: ItemMaterial.GetConsumable()),
                new ItemSubClass(6, "物品附魔", material: ItemMaterial.GetConsumable()),
                new ItemSubClass(7, "绷带", material: ItemMaterial.GetConsumable()),
                new ItemSubClass(8, "其它", material: ItemMaterial.GetConsumable())
            };
        }
    }
}